package com.labtalk.admin.service.impl;

import com.labtalk.admin.pojo.common.ResponseVo;
import com.labtalk.admin.service.InfoService;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@Service
public class InfoImpl implements InfoService {
    @Override
    public ResponseVo getInfo() {
        // 获取会话对象
        SecurityContext context = SecurityContextHolder.getContext();
        // 获取认证对象
        Authentication authentication = context.getAuthentication();
        // 获取登录用户信息
        Object userModel = authentication.getPrincipal();
        return ResponseVo.success(200, "success", userModel);
    }

    @Override
    public ResponseVo getPassword(String password) {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        String encodedPassword = passwordEncoder.encode(password);
        return ResponseVo.success(200, "success", encodedPassword);
    }
}
